package geektime.spring.springbucks.mapper;

import geektime.spring.springbucks.model.BaseEntity;
import geektime.spring.springbucks.model.CoffeeOrder;
import geektime.spring.springbucks.model.OrderState;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface CoffeeOrderMapper {
    @Insert("insert into t_order (create_time,update_time,customer,state) values (now(),now(),#{customer},#{state})")
    @Options(useGeneratedKeys = true)
    Long createOrder(Map c);

    @Insert("insert into t_order_coffee (coffee_order_id,items_id) values (#{coffee_order_id},#{items_id})")
    int createOrderCoff(Map c);

    @Update("update t_order set state=#{state} where id=#{id}")
    int updateState(@Param("state") int i, @Param("id") Long id);

    @Select("select t.id,t.customer,t.state,t.create_time,t.update_time,c.name,c.price " +
            "from t_order_coffee r " +
            "left join t_order t on r.coffee_order_id=t.id " +
            "left join t_coffee c on r.items_id=c.id " +
            "where coffee_order_id=#{id}")
    List<Map> selectorder(@Param("id") Long id);
    @Select("select count(1) " +
            "from t_order_coffee r " +
            "left join t_order t on r.coffee_order_id=t.id " +
            "left join t_coffee c on r.items_id=c.id " +
            "where coffee_order_id=#{id}")
    int selectordercount(@Param("id") Long id);

    @Delete("delete from t_order where id=#{id}")
    int deleteorder(@Param("id") Long id);

    @Delete("delete from t_order_coffee where coffee_order_id=#{id}")
    int deleteordercoffe(@Param("id") Long id);

}
